import 'package:flutter/material.dart';

class ColorAnimationDemo extends StatefulWidget {
  @override
  _ColorAnimationDemoState createState() => _ColorAnimationDemoState();
}

class _ColorAnimationDemoState extends State<ColorAnimationDemo> with SingleTickerProviderStateMixin{
  Animation<Color> _animation;
  AnimationController _controller;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(duration: Duration(milliseconds: 1000),vsync: this);
    _animation = ColorTween(begin: Colors.red,end: Colors.blue).animate(_controller);
    _controller.addListener((){
      setState(() {

      });
    });
  }

  @override
  void dispose ()
  {
    _controller.dispose();
    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('颜色动画'),
      ),
      body: Container(
        child: Column(
          children: <Widget>[
            Container(
              width: 320,
              height: 320,
              color: _animation.value,
            ),
            RaisedButton(
              child: Text('动画开始'),
              onPressed: (){
                _controller.forward();
              },
            )
          ],
        ),
      ),
    );
  }
}